from setuptools import Command, setup


class run_audit(Command):
    """Audits source code using PyFlakes for following issues:
        - Names which are used but not defined or used before they are defined.
        - Names which are redefined without having been used.
    """
    description = "Audit source code with PyFlakes"
    user_options = []

    def initialize_options(self):
        all = None

    def finalize_options(self):
        pass

    def run(self):
        import os
        import sys
        try:
            import pyflakes.scripts.pyflakes as flakes
        except ImportError:
            print "Audit requires PyFlakes installed in your system."""
            sys.exit(-1)

        dirs = ['pgate', 'tests']
        warns = 0
        for dir in dirs:
            for filename in os.listdir(dir):
                if filename.endswith('.py') and filename != '__init__.py':
                    warns += flakes.checkPath(os.path.join(dir, filename))
        if warns > 0:
            print ("Audit finished with total %d warnings." % warns)
        else:
            print ("No problems found in sourcecode.")

setup(
    name='PartnerGate',
    version='0.2',
    url='http://wwww.buzzfeed.com/',
    license='',
    author='',
    author_email='partner.gate@buzzfeed.com',
    description='PartnerGate Redo.',
    long_description=__doc__,
    packages=['pgate'],
    include_package_data=True,
    zip_safe=False,
    platforms='any',
    test_suite='nose.collector',
    install_requires=[
        'flask',
        'sqlalchemy',
        'flask-sqlalchemy',
        'MySQL-python',
    ],
    tests_require=[
        'nose',
        'mox',
    ],
    classifiers=[],
    cmdclass={'audit': run_audit}
)
